package com.tmall.qatest.util;

import com.taobao.dpservice.domain.order.LogisticsDO;
import com.taobao.dpservice.domain.order.OrderMessageDO;
import com.taobao.dpservice.domain.order.PurchaseOrderDO;
import com.taobao.dpservice.domain.order.SubPurchaseOrderDO;
import com.taobao.dpservice.notify.client.SubPurchaseOrderMsgDO;
import com.taobao.dpservice.service.PurchaseOrderReadService;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * User: cangfeng.mxf
 * Date: 13-2-26
 * Time: 下午4:46
 * Tool Class of Dpc
 */
public class DpcHelper {
    @Resource
    protected static PurchaseOrderReadService purchaseOrderReadService;
    /**
     * @param : 采购单子单DO
     * @return: 采购单子单消息DO，用作notify发送
     */
    public static SubPurchaseOrderMsgDO convert(SubPurchaseOrderDO suborder){
        if(null == suborder){
            return null;
        }
        SubPurchaseOrderMsgDO msg = new SubPurchaseOrderMsgDO();
        //获取主单
        PurchaseOrderDO mainorder = suborder.getPurchaseOrder();
        if(null != mainorder){
            //填写主单信息
            msg.setMainLogisticsStatus(mainorder.getLogisticsStatus());
            msg.setMainOrderFinish(true);
            msg.setMainPayStatus(mainorder.getPayStatus());
            msg.setMainRefundStatus(mainorder.getRefundStatus());
        }
        //获取物流单
        LogisticsDO logistics = mainorder.getLogisticsDO();
        if(null != logistics){
            //填写物流信息
            msg.setAddress(logistics.getAddress());
            msg.setArea(logistics.getArea());
            msg.setCity(logistics.getCity());
            msg.setProv(logistics.getProv());
            msg.setPostFee(Integer.parseInt(logistics.getPost())); // FIXME
        }

        for(OrderMessageDO msgVal : suborder.getMessageList()){
            if(msgVal.isDistributorMessage()){
                msg.setDistributorMessagePath(suborder.getMessagePath());
            }
            if(msgVal.isSupplierMessage()){
                msg.setSupplierMemoPath(suborder.getMessagePath());
            }
        }

        msg.setAdjustFee(suborder.getAdjustFee());
        msg.setAuctionPrice(Long.parseLong(suborder.getAuctionPrice()));
        msg.setBrandId(suborder.getBrandId());
        msg.setBuyAmount(suborder.getBuyAmount());
        msg.setCategoryId(suborder.getCategoryId());
        msg.setConsignTime(suborder.getConsignTime());
        msg.setDistributorMessagePath(suborder.getMessagePath());
        msg.setDistributorNick(suborder.getDistributor().getUserName());
        msg.setDistributorOuterId(suborder.getDistributorTaobaoId());
        msg.setEndTime(suborder.getEndTime());
        msg.setFullName(suborder.getDistributor().getUserName());
        msg.setGmtCreate(suborder.getGmtCreate());
        msg.setGmtModified(suborder.getGmtModified());
        msg.setLogisticsCompany(suborder.getLogisticsCompany());
        msg.setLogisticsNo(suborder.getLogisticsNo());
        msg.setLogisticsShipping(suborder.getLogisticsShipping());
        msg.setLogisticsStatus(suborder.getLogisticsStatus());

        msg.setMobilePhone(suborder.getDistributor().getMobilePhone());
        msg.setOriginalTotalFee(new Long(suborder.getOriginalPrice()));
        msg.setOutPayId(suborder.getWlbOrderCode());
        msg.setPayFee(suborder.getActualPrice());
        msg.setPayTime(suborder.getPayTime());
        msg.setPayType(suborder.getPayType());
        msg.setPhone(suborder.getDistributor().getPhone());

        msg.setProductId(suborder.getProductId());
        msg.setProductNumber(suborder.getProductNumber());
        msg.setProductPrice(suborder.getProductPrice());
        msg.setProductTitle(suborder.getProductTitle());
        msg.setPurchaseOrderId(suborder.getPurchaseOrderId());
        msg.setRefundFee(suborder.getRefundFee());
        msg.setRefundStatus(suborder.getRefundStatus());
        msg.setSjcItemId(suborder.getSjcItemId());
        msg.setSkuId(Long.parseLong(suborder.getSkuId()));
        msg.setSkuNumber(suborder.getSkuNumber());
        msg.setSubListAmount(mainorder.getSubOrderIdList().size());
        msg.setSubOrderId(suborder.getSubOrderId());
        msg.setPurchaseOrderId(suborder.getPurchaseOrderId());
        msg.setSubTcOrderId(suborder.getSubTcOrderId());
        msg.setSupplierFlag(suborder.getSupplier().getMessageTagDO());
        msg.setSupplierMemoPath();
        msg.setSupplierNick(suborder.getSupplier().getUserName());
        msg.setSupplierOuterId(suborder.getSupplierTaobaoId());
        msg.setTcActualPaidfee(suborder.getConfirmPaidFee());

        return msg;
    }
}
